<template>
	<div style="width: 100%;">
		<div style="display: flex; width: 100%;">
			<el-link style="width: 8%;" @click="goremark()"> 返回评论管理</el-link>
			<div style="width: 100%;"><p style="text-align: center;">{{data.a}}</p></div>
		</div>
		<div style="background-color: #E1337F;height: 0.1rem;"></div>
		<el-card >
		<div style="width: 100%;">
			<el-main>
				<h2 style="text-align: center;">{{data.a}}</h2>
				<div style="margin-left: 40rem;">
				<el-form :model="data.remark" :rules="rules" ref="formRef">
					<el-form-item label="评论编号:" prop="remid">
						 <el-input v-model="data.remark.remid" placeholder="评论编号" :prefix-icon="Cellphone" style="width: 16rem;" disabled=""/>
					</el-form-item>
					<el-form-item label="评论商品:">
						<el-select v-model="data.remark.commodity.comid" placeholder="评论商品" style="width: 255px">
							<el-option v-for="item in data.coms" :label="item.comname" :value="item.comid"/>
						</el-select>
					</el-form-item>
					<el-form-item label="评价:">
						<div style="margin-left: 3rem;">
							<el-rate  v-model="data.remark.rate" clearable  :texts="data.rat" show-text=""/>
						</div>
					</el-form-item>
					<el-form-item label="评论内容:">
						<el-input
						    v-model="data.remark.content"
						    style="width: 16rem;"
						    :rows="8"
						    type="textarea"
						    placeholder="评论内容"
							:prefix-icon="UserFilled"
						  />
											     
						
					</el-form-item>
					
				</el-form>
				<el-button  @click="add()" style="background-color: #E1337F;  margin-left: 6rem;color: #FFFFFF;">{{data.a}}</el-button>
				</div>
			</el-main>
		
		</div>
		</el-card>
		</div>
</template>

<script lang="ts" setup>
	import {ref, reactive,onMounted,computed} from"vue"
		import {$get,$postx,$postj,$postf} from '../../ajax/index.js'
		import { ElMessage, ElMessageBox } from 'element-plus'
		import router from"../../router/index.js"
		import store from "../../store/index.js"
		import {Search,ShoppingCart,Plus,EditPen,UserFilled} from '@element-plus/icons-vue'
		import bottom from "../../components/bottom.vue"
		import {useRoute} from "vue-router"
		import {success,warning,message,errors} from '../../store/alert.js'
		const route =useRoute()
		const data=reactive({
			remark:{remid:0,commodity:{comid:undefined},rate:0,content:undefined},
			a:"添加评论",
			coms:[],
			rat:['差劲', '一般', '良好', '优秀', '完美']
		})		
		function goremark(){
			router.push("/adm/admremark")
		}
		
		function add(){
			
			let fd =new FormData()
			fd.append("remid",data.remark.remid)
			fd.append("commodity.comid",data.remark.commodity.comid)
			fd.append("rate",data.remark.rate)
			fd.append("content",data.remark.content)
			let s="/adm/remark/add"
			if(data.remark.remid!=0)s="/adm/remark/update"
			$postf(s,fd).then((read)=>{
				success(read.data.msg)
				router.push("/adm/admremark")
			})
		}
		
		onMounted(()=>{
			let s=route.query.remid
			if(s==null){
				$get("/adm/remark/GoUpdate").then((read)=>{
					data.coms=read.data.data					
				})
			}else{
				$get("/adm/remark/findByid/"+s).then((read)=>{
					data.remark=read.data.data.remark
					data.coms=read.data.data.coms
					
				})
			}
			
		})
		
</script>

<style>
</style>
